//
//  SISSTenantTakeLookRecordViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2017/12/26.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSTenantTakeLookRecordViewController.h"

#import "SISSTenantTakeLookCell.h"
#import "SISSTenantTakeLookDetailViewController.h"
#import "SISSAddTenantTakeLookViewController.h"
#import "SISSNetworkingManager+TenantProgress.h"
#import "SISSTenantProgressModel.h"
//#import "SISSTenantProgressRecordInfoModel.h"

#import "SISSTenantTakeLookModel.h"

@interface SISSTenantTakeLookRecordViewController ()<SISSTenantTakeLookCellDelegate>

/* 带看模型数组 */
@property (strong, nonatomic) NSArray<SISSTenantTakeLookModel *> *takeLookArr;

@end

@implementation SISSTenantTakeLookRecordViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[SISSTenantTakeLookCell class] forCellReuseIdentifier:tenantTakeLookCellReuseID];
    
    
    WeakSelf
    [kSISSRefresh prepareHeaderRefresh:self.tableView loadDataBlock:^{
        kSISSRefresh.refreshType = SISSRefressTypeUpDown;
        [weakSelf upDownLoadData];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self requestTenantTakeLookRecordData];
}

- (void)addRecordButtonDidClickAction {
    [super addRecordButtonDidClickAction];
    //    if (self.TenantProgressRecordInfoModel.businessStatus == 2) {
    //        [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
    //        return;
    //    }
    SISSAddTenantTakeLookViewController *vc = [[SISSAddTenantTakeLookViewController alloc] init];
    vc.tenantProgressModel = self.tenantProgressModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.takeLookArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SISSTenantTakeLookCell *cell = [tableView dequeueReusableCellWithIdentifier:tenantTakeLookCellReuseID forIndexPath:indexPath];
    cell.delegate = self;
    cell.isOneButton = YES;
    cell.tenantTakeLookModel = self.takeLookArr[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    SISSTenantTakeLookDetailViewController *vc = [[SISSTenantTakeLookDetailViewController alloc] init];
    vc.tenantProgressModel = self.tenantProgressModel;
    //    vc.brokerState = self.takeLookArr[indexPath.row].brokerState;
    vc.takeLookModel = self.takeLookArr[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -- SISSTenantTakeLookCellDelegate
- (void)tenantTakeLookCell:(SISSTenantTakeLookCell *)cell clickButtonWithIndex:(NSInteger)index {
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    SISSAddTenantTakeLookViewController *vc = [[SISSAddTenantTakeLookViewController alloc] init];
    vc.tenantProgressModel = self.tenantProgressModel;
    vc.takeLookModel = self.takeLookArr[indexPath.row];
    vc.isPerfectEnter = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 加载数据
- (void)upDownLoadData {
    
    [self requestTenantTakeLookRecordData];
}

#pragma mark -- 获取出租带看记录数据
- (void)requestTenantTakeLookRecordData {
    
    WeakSelf
    [kNetworkManager requestTenantTakelookRecordWithArbpId:self.tenantProgressModel.arbpId success:^(NSArray<SISSTenantTakeLookModel *> *takeLookArr) {
            weakSelf.takeLookArr = takeLookArr;
    
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [weakSelf.tableView reloadData];
                [weakSelf.tableView.mj_header endRefreshing];
            }];
    
        } failed:^(NSError *error) {
    
            [weakSelf.tableView.mj_header endRefreshing];
            NSLog(@"%@",error);
        }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
